const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('electronAPI', {
  loadConfig: () => ipcRenderer.invoke('load-config'),
  startCrawl: (config) => {
    console.log('startCrawl invoked with config:', config);
    return ipcRenderer.invoke('start-crawl', config);
  },
  saveConfig: (config) => {
    console.log('saveConfig invoked with config:', config);
    return ipcRenderer.invoke('save-config', config);
  },
  loadSavedConfigs: () => ipcRenderer.invoke('load-saved-configs'),
  saveToExcel: (results, savePath) => {
    console.log('saveToExcel invoked with results:', results, 'savePath:', savePath);
    return ipcRenderer.invoke('save-to-excel', results, savePath);
  },
  onUpdate: (callback) => {
    ipcRenderer.on('crawl-update', (event, data) => callback(data));
  },
  selectDirectory: () => ipcRenderer.invoke('select-directory')
});